package com.reptile.service.impl;

import com.reptile.service.RetryService;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 测试重试方法实现
 * @author songyafei
 */
@Service
public class RetryServiceImpl implements RetryService {

    @Override
    @Transactional(rollbackFor = Exception.class)
    @Retryable(value = Exception.class,maxAttempts = 3,
            backoff = @Backoff(delay = 5000, multiplier = 1, maxDelay = 10000))
    public void retryTransferAccounts(int fromAccountId, int toAccountId, float money) throws Exception {
        System.out.println("我重试了！！！");
        int a = 2 / 0;
        throw new Exception();
    }

    @Recover
    public void recover(Exception e) {
        System.out.println("回调方法执行！！！");
    }
}
